home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / basic / x10cmd.bas < prev    next >
BASIC Source File  |  1992-05-12  |  3KB  |  109 lines

  1.  
  2. REM
  3. REM X10 basic interface code by Matt Drury (for demo purposes, enhancement)
  4. REM turns on, off, or dims one X10 module - any housecode or unit
  5. REM
  6. REM feel free to modify at will; distribution with these credits required,
  7. REM as well as your own enhancement credits. Please send me a copy of it!
  8. REM
  9. REM Home-automation support coming via London BBS at 407/423-5226 (1:363/69)
  10. REM Feel free to Mail me on CompuServe at [75300,1610] as well
  11. REM
  12. REM * assumes com1 (change open statement if needed)
  13. REM * does not look for the status bit returned
  14. REM
  15.  
  16.  
  17.  
  18. CLS
  19. DEFSTR A-C: DEFINT D-Z
  20.  
  21. REM below statements for future expansion
  22. DIM al(16, 16): REM location names (LivRoom, etc)
  23. DIM an(16, 16): REM module names (Light, Toaster, etc)
  24.  
  25.  
  26.  
  27. gethouse:
  28. PRINT "Enter the house code (A-P): "; : GOSUB getchar: ah = UCASE$(ai)
  29. IF ah < "A" OR ah > "P" THEN GOTO gethouse
  30.  
  31. getunit:
  32. INPUT "Enter the unit code (1-16)"; un
  33. IF un < 1 OR un > 16 THEN GOTO getunit
  34.  
  35. getcommand:
  36. PRINT "Enter [1]On, [2]Off, [3]Dim"; : GOSUB getchar: ac = ai
  37. IF ac < "1" OR ac > "3" THEN GOTO getcommand
  38.  
  39. getperc:
  40. IF ac = "3" THEN INPUT "Percentage of brightness"; perc: IF perc < 0 OR perc > 100 THEN GOTO getperc
  41.  
  42. PRINT
  43. PRINT "Sending command, please wait."
  44.    
  45. OPEN "COM1:600,N,8,1,CD0,CS0,DS0,OP0,RS,TB2048,RB2048" FOR RANDOM AS #1
  46.  
  47. sendsync:
  48. FOR i = 1 TO 16
  49. PRINT #1, CHR$(255); : REM bytes 1-16
  50. NEXT i
  51.  
  52. sendDirectCommandID:
  53. PRINT #1, CHR$(1); : REM byte 17
  54.  
  55. sendfunction:
  56. x = 0: REM will be byte 18 (level/function)
  57.  
  58. computelevel:
  59. p1 = 100 - perc
  60. IF p1 > 50 THEN x = x + 128: p1 = p1 - 50
  61. IF p1 > 25 THEN x = x + 64: p1 = p1 - 25
  62. IF p1 > 12 THEN x = x + 32: p1 = p1 - 12
  63. IF p1 > 6 THEN x = x + 16: p1 = p1 - 6
  64.  
  65. computefunction:
  66. IF ac = "1" THEN x = x + 2: REM on
  67. IF ac = "2" THEN x = x + 3: REM off
  68. IF ac = "3" THEN x = x + 5: REM dim
  69.  
  70. PRINT #1, CHR$(x); : REM byte 18 (level/function)
  71.  
  72. sendhousecode:
  73.  
  74. REM housecode database * 16 is below; A-P sequential
  75. DATA 6,14,2,10,1,9,5,13,7,15,3,11,0,8,4,12
  76.  
  77. FOR i = 1 TO ASC(ah) - 64: READ n: NEXT i
  78. y = n * 16: PRINT #1, CHR$(y); : REM byte 19 (housecode)
  79.  
  80. sendmodulebitmap:
  81. IF un > 8 THEN z2 = 1: un = un - 9 ELSE z2 = 0: un = un - 1
  82. z = 2 ^ (7 - un)
  83.  
  84. IF z2 = 1 THEN PRINT #1, CHR$(z); : PRINT #1, CHR$(0);
  85. IF z2 = 0 THEN PRINT #1, CHR$(0); : PRINT #1, CHR$(z);
  86.  
  87. xsum = x + y + z
  88.  
  89. WHILE xsum > 255
  90.    xsum = xsum - 256
  91. WEND
  92.  
  93. PRINT #1, CHR$(xsum); : REM byte 22 (Checksum)
  94.  
  95. RUN
  96.  
  97. getchar:
  98. ai = INKEY$: IF ai = "" THEN GOTO getchar ELSE PRINT ai: RETURN
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.